package com.liushao.controller;


import com.liushao.entity.LendItemReturn;
import com.liushao.result.Result;
import com.liushao.service.LendItemReturnService;
import com.liushao.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 标的出借回款记录表 前端控制器
 * </p>
 *
 * @author chen
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/api/core/lendItemReturn")
public class LendItemReturnController {

    @Autowired
    private LendItemReturnService lendItemReturnService;

    //  .$get('/api/core/lendItemReturn/list/' + this.$route.params.id)

    @ApiOperation("获取列表")
    @GetMapping("/list/{lendId}")
    public Result list(
            @ApiParam(value = "标的Id",required = true)
            @PathVariable Long lendId, HttpServletRequest request
            ){

        
        String token = null;
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies){
            if(cookie.getName().equals("token")){
                token = cookie.getValue();
                break;
            }
        }
        Long userId = JwtUtils.getUserId(token);

      List<LendItemReturn> lendItemReturnList= lendItemReturnService.selectByLendId(lendId,userId);


      return Result.ok().data("list",lendItemReturnList);



    }


}

